/**
 * 工具统一导出 - IntelliMark版
 */

// 导出所有工具
export * from './textGeneration/textGenerationTool'
export * from './textAnalysis/textAnalysisTool'
export * from './memoryManagement/memoryManagementTool'
export * from './projectManagement/projectManagementTool'

// 导出工具类型
export type {
  BaseTool,
  ToolCategory,
  ToolResult,
  TextGenerationParams,
  TextAnalysisParams,
  MemoryManagementParams,
  ProjectManagementParams,
} from '../types/tools'

// 导出便捷创建函数
export {
  createTextGenerationTool,
  defaultTextGenerationTool
} from './textGeneration/textGenerationTool'

export {
  createTextAnalysisTool,
  defaultTextAnalysisTool
} from './textAnalysis/textAnalysisTool'

export {
  createMemoryManagementTool,
  defaultMemoryManagementTool
} from './memoryManagement/memoryManagementTool'

export {
  createProjectManagementTool,
  defaultProjectManagementTool
} from './projectManagement/projectManagementTool'

// 工具管理器
export class ToolManager {
  private static instance: ToolManager
  private tools: Map<string, any> = new Map()

  private constructor() {
    this.initializeDefaultTools()
  }

  public static getInstance(): ToolManager {
    if (!ToolManager.instance) {
      ToolManager.instance = new ToolManager()
    }
    return ToolManager.instance
  }

  private initializeDefaultTools(): void {
    // 注册默认工具
    this.tools.set('text-generation', defaultTextGenerationTool)
    this.tools.set('text-analysis', defaultTextAnalysisTool)
    this.tools.set('memory-management', defaultMemoryManagementTool)
    this.tools.set('project-management', defaultProjectManagementTool)
  }

  public registerTool(name: string, tool: any): void {
    this.tools.set(name, tool)
  }

  public getTool(name: string): any {
    return this.tools.get(name)
  }

  public getAllTools(): Map<string, any> {
    return new Map(this.tools)
  }

  public listTools(): string[] {
    return Array.from(this.tools.keys())
  }

  public async executeTool(name: string, input: any): Promise<any> {
    const tool = this.getTool(name)
    if (!tool) {
      throw new Error(`Tool not found: ${name}`)
    }
    return await tool.execute(input)
  }
}

// 导出便捷函数
export const getToolManager = (): ToolManager => {
  return ToolManager.getInstance()
}